import HKWebPluginPlayer from './HKWebPluginPlayer.vue';
import FrameMixin from '../player-frame/FrameMixin.jsx';

export default {
  name: 'HKPlayer',
  mixins: [FrameMixin],
  components: { HKWebPluginPlayer },
  data() {
    return { playerProps: {} };
  },
  methods: {
    onVideoOptionChange() {
      const { cameraCode, startTime, endTime } = this.videoOption;
      const props = { cameraCode };
      if (this.isPlayback === true) {
        props.startTime = startTime.unix();
        props.endTime = endTime.unix();
      }
      this.playerProps = Object.assign(props, {
        isPlayback: this.isPlayback === true,
        toolBar: this.fullMode === true,
      });
    },
  },
  render() {
    return this.renderTemplate(() => (
      <HKWebPluginPlayer
        {...{
          props: this.playerProps,
          on: {
            select: this.onVideoSelect,
            close: this.onVideoClose,
            closeDialog: () => this.$emit('closeDialog'),
          },
        }}
      />
    ));
  },
};
